package com.api.common;

import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        int total = Integer.valueOf(scanner.nextLine());
        
        AlertTrigger alertTrigger = new TimeAlertTrigger(total);
        
        
        for(int i = 0; i < total; i++) {
            //创建具体观察者
            String name = scanner.nextLine();
            Student student = new Student(name);
            //注册    
            alertTrigger.addStudent(student);
        }
        
        int updateTimes = Integer.valueOf(scanner.nextLine());
        for(int i = 0; i < updateTimes; i++) {
            alertTrigger.update();
        }
    }
}


abstract class AlertTrigger {
    
    //观察者当前数目
    private int size;   
    
    //观察者最大数目
    private int limit;
    
    //时间,对于子类可见
    protected int time = 0;
    
    //存储观察者集合
    private List<Student> students = new ArrayList<>();
    
    public void addStudent(Student student) {
        if(size == limit) {
            throw new RuntimeException("Exceed max observers!");
        }
        students.add(student);
        size++;
    }
    
    public void deleteStudent(Student student) {
        students.remove(student);
    }
    
    //通知所有监听者
    public void notifyAllStudents() {
        for(Student s : students) {
            //传入观察目标
            s.alert(this);
        }
    }
    
    public void setSize(int size){
        this.size = size;
    }
    
    public void setLimit(int limit) {
        this.limit = limit;
    }
    
    // 获取当前数目
    public int getSize() {
        return this.size;
    }
    
    // 获取最大数目
    public int getLimit(){
        return this.limit;
    }
    
    // 获取时间方式
    protected abstract int getTime();
    
    // 更新
    protected abstract void update();
    
}

class TimeAlertTrigger extends AlertTrigger {
    
    //初始化父类属性
    TimeAlertTrigger(int limit) {
        super.setLimit(limit);
        super.setSize(0);
    }
    
    @Override
    protected int getTime() {
        return super.time % 12;
    }
    
    @Override
    protected void update() {
        super.time++;       //每次更新 + 1
        super.notifyAllStudents();
    }
}


// 观察者
interface Observer {
    
    //方案二: 回调观察对象实现提醒时间
    void alert(AlertTrigger alertTrigger);
}


// 具体观察者
class Student implements Observer{
    
    private String name;
    
    public Student(String name) {
        this.name = name;
    }
    
    public String getName() {
        return this.name;
    }
    
    @Override
    public void alert(AlertTrigger alertTrigger) {
        System.out.println(getName() + " " + alertTrigger.getTime());
    }
}
